package com.hospital.workstation.webService.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import lombok.Data;

import javax.print.DocFlavor;
import java.util.Date;
import java.util.Map;

/**
 * @Author:HYZ
 * @Date:2023-2-28
 */
public class Response {
    private Header Header;
    private Body Body;

    public void setHeader(String messageID, String sourceSystem) {
        this.Header = new Header();
        this.Header.setMessageID(messageID);
        this.Header.setSourceSystem(sourceSystem);
    }

    public void setBody(String resultCode, String resultContent) {
        this.Body = new Body();
        this.Body.setResultCode(resultCode);
        this.Body.setResultContent(resultContent);
    }

    @Data
    class Body {
        private String ResultCode = "0";
        private String ResultContent = "成功";
    }


    public String getXml() {
        String xml = "<Response><Header><SourceSystem>" + this.Header.getSourceSystem()
            + "</SourceSystem><MessageID>" + this.Header.getMessageID()
            + "</MessageID></Header><Body><ResultCode>" + this.Body.getResultCode()
            + "</ResultCode><ResultContent>" + this.Body.getResultContent()
            + "</ResultContent></Body></Response>";
        return xml;
    }

    /**
     * 拼接病历信息请求xml
     *
     * @param inpNo 就诊号
     * @return
     */
    public String getMES0181Xml(String inpNo) {
        String xml = "<Request>" +
            "<Header>" +
            "<SourceSystem>SYS0042</SourceSystem>" +
            "<MessageID>MES0181</MessageID>" +
            "</Header>" +
            "<AdmissionRecord_Requset>" +
            "<TransID>1</TransID>" +
            "<inp_no>" + inpNo + "</inp_no>" +
            "<patient_id></patient_id>" +
            "<patient_name></patient_name>" +
            "</AdmissionRecord_Requset>" +
            "</Request>";
        return xml;
    }

    /**
     * 第一次生命体征数据
     *
     * @param inpNo 就诊号
     * @return
     */
    public String getMES0183Xml(String inpNo) {
        String xml = "<Request>" +
            "<Header>" +
            "<SourceSystem>SYS0042</SourceSystem>" +
            "<MessageID>MES0183</MessageID>" +
            "</Header>" +
            "<Body>" +
            "<VitalSignInfoRt>" +
            "<PAADMVisitNumber>" + inpNo + "</PAADMVisitNumber>" +
            "</VitalSignInfoRt>" +
            "</Body>" +
            "</Request>";
        return xml;
    }

    /**
     * 诊断信息xml
     *
     * @return
     */
    public String getMES0073Xml() {
        String xml = "<Request><Header><SourceSystem>02</SourceSystem><MessageID>838988</MessageID></Header><Body><AddDiagnosisRt><BusinessFieldCode>00001</BusinessFieldCode><HospitalCode>HNZYYDXDYFSYY</HospitalCode><PATPatientID>0007092665</PATPatientID><PAADMVisitNumber>9011544</PAADMVisitNumber><PAADMEncounterTypeCode>I</PAADMEncounterTypeCode><PAADMDiagnoseList><PAADMDiagnose><PADDiagId>9011540||1</PADDiagId><PADDiagCode>O26.900x506</PADDiagCode><PADDiagDesc>孕39周</PADDiagDesc><PADDiagTypeCode>C008</PADDiagTypeCode><PADDiagTypeDesc>入院诊断</PADDiagTypeDesc><PADDiagStatus>待诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks>+1d</PADRemarks><PADDiagCat>西医</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose><PAADMDiagnose><PADDiagId>9011540||2</PADDiagId><PADDiagCode>O47.900x002</PADDiagCode><PADDiagDesc>先兆临产</PADDiagDesc><PADDiagTypeCode>C008</PADDiagTypeCode><PADDiagTypeDesc>入院诊断</PADDiagTypeDesc><PADDiagStatus>确诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks></PADRemarks><PADDiagCat>西医</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose><PAADMDiagnose><PADDiagId>9011540||3</PADDiagId><PADDiagCode>O26.900x603</PADDiagCode><PADDiagDesc>孕2次</PADDiagDesc><PADDiagTypeCode>C008</PADDiagTypeCode><PADDiagTypeDesc>入院诊断</PADDiagTypeDesc><PADDiagStatus>确诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks></PADRemarks><PADDiagCat>西医</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose><PAADMDiagnose><PADDiagId>9011540||4</PADDiagId><PADDiagCode>O26.900x701</PADDiagCode><PADDiagDesc>产0次</PADDiagDesc><PADDiagTypeCode>C008</PADDiagTypeCode><PADDiagTypeDesc>入院诊断</PADDiagTypeDesc><PADDiagStatus>确诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks></PADRemarks><PADDiagCat>西医</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose><PAADMDiagnose><PADDiagId>9011540||5</PADDiagId><PADDiagCode>Z87.500x005</PADDiagCode><PADDiagDesc>不良孕产个人史</PADDiagDesc><PADDiagTypeCode>C008</PADDiagTypeCode><PADDiagTypeDesc>入院诊断</PADDiagTypeDesc><PADDiagStatus>确诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks></PADRemarks><PADDiagCat>西医</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose><PAADMDiagnose><PADDiagId>9011540||6</PADDiagId><PADDiagCode>O69.101</PADDiagCode><PADDiagDesc>脐带绕颈</PADDiagDesc><PADDiagTypeCode>C008</PADDiagTypeCode><PADDiagTypeDesc>入院诊断</PADDiagTypeDesc><PADDiagStatus>确诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks>1周</PADRemarks><PADDiagCat>西医</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose><PAADMDiagnose><PADDiagId>9011540||7</PADDiagId><PADDiagCode>A09.02.03.</PADDiagCode><PADDiagDesc>胎孕类病</PADDiagDesc><PADDiagTypeCode>C008</PADDiagTypeCode><PADDiagTypeDesc>入院诊断</PADDiagTypeDesc><PADDiagStatus>确诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks></PADRemarks><PADDiagCat>中医</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose><PAADMDiagnose><PADDiagId>9011540||8</PADDiagId><PADDiagCode>B04.06.03.05.01</PADDiagCode><PADDiagDesc>脾肾两虚证</PADDiagDesc><PADDiagTypeCode>C008</PADDiagTypeCode><PADDiagTypeDesc>入院诊断</PADDiagTypeDesc><PADDiagStatus>确诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks></PADRemarks><PADDiagCat>证型</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose><PAADMDiagnose><PADDiagId>9011540||9</PADDiagId><PADDiagCode>E78.500</PADDiagCode><PADDiagDesc>高脂血症</PADDiagDesc><PADDiagTypeCode>BCDIS</PADDiagTypeCode><PADDiagTypeDesc>补充诊断</PADDiagTypeDesc><PADDiagStatus>确诊</PADDiagStatus><PADDiagDocCode>9256</PADDiagDocCode><PADDiagDocDesc>卢喜洋</PADDiagDocDesc><PADDiagCategory>1</PADDiagCategory><PADDiagDate>2023-03-23</PADDiagDate><PADDiagTime>09:21:57</PADDiagTime><PADRemarks></PADRemarks><PADDiagCat>西医</PADDiagCat><DiagFlag>N</DiagFlag></PAADMDiagnose></PAADMDiagnoseList><UpdateUserCode>-</UpdateUserCode><UpdateDate>2023-03-23</UpdateDate><UpdateTime>09:22:11</UpdateTime></AddDiagnosisRt></Body></Request>";
        return xml;
    }

    /**
     * MES0181，HIS病历信息接口返回xml数据
     *
     * @return
     */
    public String getMedicationInfoXml() {
        String xml = "<Response><ResultCode>0</ResultCode><ResultMsg>成功</ResultMsg><ret_data><hospital_id>HNZYYDXDYFSYY</hospital_id><patient_id>0005083666</patient_id><mr_no>20803548</mr_no><inp_no>9174763</inp_no><admission_ward></admission_ward><PAADM_InPatNo>8</PAADM_InPatNo><bed_no></bed_no><patient_name></patient_name><sex></sex><date_of_birth></date_of_birth><birth_place></birth_place><occupation_type></occupation_type><clan></clan><marital_status></marital_status><contact_addr></contact_addr><admission_datetime></admission_datetime><representor></representor><representor_type_code></representor_type_code><representor_type></representor_type><lxrdh></lxrdh><lxr></lxr><yblx></yblx><gmjl></gmjl><recorder_id></recorder_id><recorder_name></recorder_name><chief_complaints>肾移植术后1年，右胸部疼痛3月余，加重1周</chief_complaints><present_history>患者1年前因慢性肾衰竭 尿毒症期于我科行“同种异体肾移植”，手术顺利，术后予以抗排斥、抗感染、控制血压、护肝、营养支持等对症治疗，病情稳定后出院，院外病情稳定。3月前无明显诱因出现右胸部疼痛，于我院住院治疗，诊断为“急性胆囊炎”，经抗炎止痛治疗后病情好转出院。1周前上述症状加重，右胸部间断性疼痛，空腹时明显，门诊以“移植肾功能不全”为诊断收住我科；入院症见：神志清，精神可，纳眠一般，小便少，大便溏，近期体重无明显变化。</present_history><past_history>高血压病史5年，血压最高210/120mmHg，目前血压控制正常；同种异体肾移植术后1月余；否认冠心病；否认糖尿病；否认脑梗塞；否认脑出血；否认肺结核；否认肝炎；否认其他疾病；否认输血史；预防接种史随本地进行。\n" +
            "入院前用药清单：（患者提供的用药情况）\n" +
            "药物名称\n" +
            "使用剂量\n" +
            "使用频次\n" +
            "最后用药时间\n" +
            "是否继续使用\n" +
            "他克莫司\n" +
            "麦考酚钠肠溶片\n" +
            "甲泼尼龙片\n" +
            "2.5mg\n" +
            "     360mg\n" +
            "     4mg\n" +
            "bid\n" +
            "      bid\n" +
            "      qd\n" +
            "入院前\n" +
            "是</past_history><family_history>父母体健。兄弟姐妹3人，体健。否认家族遗传病史。</family_history><personal_history></personal_history><obstetrical_history></obstetrical_history><birth_history></birth_history><menstrual_history></menstrual_history><feeding_history></feeding_history><vital_sign_t></vital_sign_t><vital_sign_p></vital_sign_p><vital_sign_r></vital_sign_r><vital_sign_bp_sys></vital_sign_bp_sys><vital_sign_bp_dia></vital_sign_bp_dia><physical_exam></physical_exam><additional_special_situations></additional_special_situations><assistant_exam_lab></assistant_exam_lab><assistant_exam_spec></assistant_exam_spec><assistant_exam_path></assistant_exam_path><assistant_exam_other></assistant_exam_other><nutrition_screening_results></nutrition_screening_results><rehabilitation_screening_results></rehabilitation_screening_results><primary_diagnosis></primary_diagnosis><record_datetime></record_datetime><admission_rytj></admission_rytj><zhuanke_jiancha>腹平坦，双腰曲线对称，双肾区无隆起，双肾区无压痛及叩击痛，双输尿管行程无压痛及反跳痛，膀胱区无隆起,无压痛。右下腹壁可见一长约15cm陈旧性手术疤痕，移植肾质地可，无明显压痛及叩击痛。</zhuanke_jiancha><fuzhu_jiancha>暂无。</fuzhu_jiancha><zhenliao_jihua></zhenliao_jihua><CriticalExt></CriticalExt><AdmRowId></AdmRowId><BloodRecord>N</BloodRecord><BloodRecordInfo></BloodRecordInfo></ret_data></Response>";
        return xml;
    }

    /**
     * MES0183，HIS第一护理数据接口返回的xml数据
     *
     * @return
     */
    public String getVitalSignInfo() {
        String xml = "<Response>" +
            "<Header>" +
            "<SourceSystem>02</SourceSystem>" +
            "<MessageID>31026718</MessageID>" +
            "</Header>" +
            "<Body>" +
            "<ResultCode>0</ResultCode>" +
            "<ResultContent>成功</ResultContent>" +
            "<VitalSignInfoList>" +
            "<VitalSignInfo>" +
            "<Weight>15</Weight>" +
            "<Pulse>94</Pulse>" +
            "<height>99</height>" +
            "<breath>23</breath>" +
            "<SystolicBP>114</SystolicBP>" +
            "<DiastolicBP>46</DiastolicBP>" +
            "<Temperature>36.3</Temperature>" +
            "<OutputQuantity></OutputQuantity>" +
            "<InputQuantity></InputQuantity>" +
            "<MeasureUserCode>2053</MeasureUserCode>" +
            "<MeasureUserName>杨艳柳</MeasureUserName>" +
            "<MeasureDate></MeasureDate>" +
            "<MeasureTime></MeasureTime>" +
            "</VitalSignInfo>" +
            "</VitalSignInfoList>" +
            "</Body>" +
            "</Response>";
        return xml;
    }

    public static void main(String[] args) {

        Response response = new Response();
        /*response.setHeader("132", "zdya");
        response.setBody("0", "成功");
        System.out.println(response.getXml());*/

        Console.log(response.getMES0181Xml("9011544"));

        Long time=1683875762218L;
        Date date = new Date(time);
        Console.log(date);
    }

}
